home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / c / amiexpress / source / ae / code / ax3.00 / download_a_file.c < prev    next >
Encoding:
C/C++ Source or Header  |  1980-01-03  |  8.7 KB  |  346 lines

  1. #include "bbs.h"
  2.  
  3.  
  4. long fsize,tfsize,dtfsize;
  5. int NumFiles;
  6. extern BOOL GET_BIT(int bitnum);
  7. /* local globals */
  8. int LineCount;
  9. int DirScan,StartDir;
  10. extern char prototitle[];
  11. extern struct ZModem ZModemInfo;
  12. extern BOOL LocalUpload;
  13. extern int XIMPort;
  14. static void ListProtocols(void)
  15. {
  16.  AEPutStr("\r\n                              [Z] AMI-Zmodem Batch");
  17. //AEPutStr("\r\n                              [X] XPR-Zmodem Batch\r\n");
  18. }
  19.  
  20. static void RecvExternal(char *fn,char *bf)
  21. {
  22. }
  23.  
  24. static void ExceedRatio(void)
  25. {
  26.  AEPutStr("You have exceeded your ratio, you must upload first.\r\n\r\n");
  27. }
  28.  
  29. static void DownloadPrompt(USHORT RatioType, long mins, long bytes, int filespec, int files, char *str)
  30. {
  31.  if(RatioType==0)
  32.         sprintf(str,"\r\n%ld mins, %ld bytes, Filespec(%d): ",mins,bytes,filespec);
  33.  if(RatioType==2)
  34.         sprintf(str,"\r\n%ld mins, %d files, Filespec(%d): ",mins,files,filespec);
  35.  if(RatioType==1)
  36.         sprintf(str,"\r\n%ld mins, %ld bytes, %d files, Filespec(%d): ",mins,bytes,files,filespec);
  37. }
  38.  
  39. static int DownloadFile(char *rfinal)
  40. {
  41.  int status;
  42.  
  43.  switch(User.Protocol) {
  44.         case 'Z':
  45.               //if(LocalUpload) { BatchASLSend(rfinal); LocalUpload=0; }
  46.             status=Zmodem_Send(rfinal);     break;
  47.         case 'C':
  48.             RecvExternal("ram:testfile","NOTHING");    break;
  49.     }
  50.  return(status);
  51. }
  52.  
  53.  
  54.  
  55. int PGoodbye(void);
  56. extern long Time_limit;
  57.  
  58. int Download_A_File(char *str)
  59. {
  60.  extern BYTE FreeDownloads,CNOZOOM,BeenUDd;
  61.  extern long SessionDnBytes;   /* used for max downloaded bytes per session */
  62.  extern struct myst my_struct;
  63.  int tsec,min,secs,x,status,mystat, nad,PROTO;
  64.  long peff,pcps,bad,Tbad;
  65.  char string[100];
  66. // char colorbuff[6]={0x1B, 0x5B, 0x33, 0x31, 0x6D, 0x00};
  67.  
  68.  PROTO=0;
  69.  nad=0;
  70.  NumFiles=0;
  71.  FreeDFlag=0;
  72.  rfinal[0]='\0';
  73.  str[0]='\0';
  74.  AEPutStr("\r\n");
  75.  if(MaxDirs==0) {
  76.      MyError(5); //Sorry();
  77.         return(FAILURE);
  78.     }
  79.  
  80.  sprintf(GSTR1,"%sDownloadMsg",Screen_Location);
  81.  if(mystat=ChecktoDisplay(GSTR1,GSTR2,0,1)) {
  82.      DoPause();
  83.         AEPutStr("\r\n");
  84.     }
  85.  
  86.  tfsize=0;
  87.  dtfsize=0;
  88.  
  89.  DisplayULStats(&User);              /* Show User stats.. Num Dnloads, uploads */
  90.  
  91.  Tbad=BytesADL;    /* User Daily Limit of bytes to dnload */
  92.  if(User.Sec_Library!=0)    {   /* Dont have a zero ratio */
  93.      if(User.Sec_Board>0) {
  94.          nad=(User.Sec_Library*(User.Uploads+1))-User.Downloads;
  95.             sprintf(string,"Files Avail before UL : %d\r\n",nad);
  96.             AEPutStr(string);
  97.          if(nad<1) {
  98.              (void)ExceedRatio();
  99.                 return(SUCCESS);
  100.             }
  101.         }
  102.      if(User.Sec_Board<2) {
  103.          bad=(User.Sec_Library*User.Bytes_Upload)-User.Bytes_Download;
  104.             sprintf(string,"Bytes Avail before UL : %ld\r\n",bad);
  105.             AEPutStr(string);
  106.          if(bad<1) {
  107.              (void)ExceedRatio();
  108.                 return(SUCCESS);
  109.             }
  110.             if(bad<BytesADL)            Tbad=bad;
  111.         }
  112.     } else      AEPutStr("Download to Upload Ratio Disabled.\r\n");
  113.  
  114. // We can replace this with User.Protocol = 'Z';
  115.  
  116.  mystat=CommandSplit();
  117.  
  118.  if(mystat>1&&(strlen(Command[1])==1)) {
  119.      PROTO=2;
  120.         strcpy(str,Command[1]);
  121.      SetProtocol(str);
  122.     } else    {
  123.      str[0]='\0';
  124.         SetProtocol(str);
  125.     }
  126.  
  127.  AEPutStr("Space between filenames.  Wildcards permitted.\r\n");
  128.  //AEPutStr("      Zmodem Uploading & Downloading only\r\n");
  129.  str[0]='\0';
  130.  Sysopdl=0;
  131.  
  132.  
  133.  
  134.  
  135.  if((Command[0][1]=='S'||Command[0][1]=='s')&&GET_BIT(ACS_SYSOP_DOWNLOAD)) {
  136.      Sysopdl=1;
  137.         sprintf(string,"\tSYSOP DOWNLOAD: %s\n",MAINMENU_Li);
  138.      (void)CallersLog(string);
  139.         (void)UDLog(string);
  140.      if(strlen(MAINMENU_Li)>4)
  141.          strcpy(str,(char *)&MAINMENU_Li[3+PROTO]);
  142.     } else    {
  143.      str[0]='\0';
  144.         if(mystat>1) {
  145.          strcpy(str,(char *)&MAINMENU_Li[1+PROTO]);
  146.             strcat(str," ");
  147.         }
  148.      if(strlen(flaglist)!=0)
  149.          strcat(str,flaglist);
  150.     }
  151.  
  152.  if(strlen(str)!=0)     goto Skip1;
  153. Arestart:
  154.  do {
  155.      tsec=dtfsize/(Online_Baud/10L);
  156.         min=tsec/60L;
  157.      if(((Time_limit/60L)-min)<0) {
  158.          AEPutStr("Not enough time for requested downloads.\r\n\r\n");
  159.             return(SUCCESS);
  160.         }
  161.      if((Tbad-tfsize)<0&&(User.Sec_Board<2)&&(User.Sec_Library!=0)) {
  162.             AEPutStr("Not enough free bytes for requested downloads.\r\n\r\n");
  163.             return(SUCCESS);
  164.      }
  165.         if((nad<FreeDFlag&&User.Sec_Board>0)&&User.Sec_Library!=0) {
  166.             AEPutStr("Not enough free files for requested number of downloads.\r\n\r\n");
  167.          return(SUCCESS);
  168.         }
  169.      if(nad==FreeDFlag&&User.Sec_Library!=0&&User.Sec_Board>0)  goto Astart;
  170.  
  171.         if(User.Sec_Library==0)
  172.             sprintf(str,"\r\n%ld mins, (Ratio Disabled), Filespec(%d): ",(Time_limit/60L)-min,(NumFiles+1));
  173.      else
  174.             DownloadPrompt(User.Sec_Board,(Time_limit/60L)-min,Tbad-tfsize,(NumFiles+1),nad-FreeDFlag,str);
  175.  
  176.      AEPutStr(str);
  177.  
  178.         status=LineInput("",str,200,KEYBOARD_TIMEOUT);
  179.      if(status<0)  return(NO_CARRIER);
  180.         if((strlen(str)==0)&&(NumFiles==0)) {
  181.          AEPutStr("\r\n");
  182.             return(SUCCESS);
  183.      }
  184.         if(strlen(str)==0)  goto Astart;
  185.      if(((str[0]=='q'||str[0]=='Q')||(str[0]=='a'||str[0]=='A'))&&strlen(str)==1) {
  186.             AEPutStr("Aborting...\r\n\r\n");
  187.             return(SUCCESS);
  188.      }
  189. Skip1:
  190.      AEPutStr("\r\nChecking...\r\n");
  191.         if(!Sysopdl) {
  192.             for(x=0;x<strlen(str);++x)    {
  193.                 if(str[x]==':' || str[x]=='/') {
  194.                     AEPutStr("\r\nYou may not include any special symbols\r\n");
  195.                    goto Arestart;
  196.                 }
  197.          }
  198.             if(str[0]=='?'||str[0]=='*') {
  199.                 AEPutStr("\r\nToo ambigious, start with at least one character.\r\n");
  200.                 goto Arestart;
  201.          }
  202.         } else {
  203.          for(x=0;x<strlen(str);++x) {
  204.                 if(str[x]=='?' || str[x]=='*' || str[x]=='#') {
  205.                     AEPutStr("\r\nSysop download doesn't support wildcards\r\n");
  206.                  goto Arestart;
  207.              }
  208.             }
  209.      }
  210.         strcat(str," ");
  211.      status=Check_list(str,rfinal);
  212.         if(status==FAILURE)  return(SUCCESS);
  213.  } while(NULL==0L);
  214.  
  215. Astart:
  216.  if(NumFiles==0)  return(SUCCESS);
  217.  switch(User.Protocol) {
  218.      case 'Z':
  219.             AEPutStr("\r\nZmodem ");    break;
  220.      case 'C':
  221.         AEPutStr("\r\nXmodem/CRC ");    break;
  222.     }
  223.  
  224.  AEPutStr(" Batch Download Estimate:\r\n");
  225.  
  226. Astart2:
  227.   tsec=dtfsize/(Online_Baud/10L);
  228.   min=tsec/60L;
  229.   secs=tsec-(min*60L);
  230.   sprintf(str,"   %d files, %ldk bytes, %d mins %d secs\r\n",NumFiles,(dtfsize/1024),min,secs);
  231.   AEPutStr(str);
  232.  
  233.  if(Tbad<tfsize) {
  234.         AEPutStr("Exceeded bytes limit.\r\n\r\n");
  235.         return(SUCCESS);
  236.     }
  237.  
  238.  
  239.  if( (my_struct.maxdbytes < tfsize) || ((my_struct.sessiondbytes+dtfsize) > my_struct.maxdbytes)) {
  240.  
  241.         AEPutStr("Exceeded BBS Max Download Limit!!\r\n\r\n");
  242.         return(SUCCESS);
  243.     }
  244.  
  245.  if(min>(Time_limit/60L)) {
  246.         AEPutStr("  Insufficent time for transfer.\r\n\r\n");
  247.         return(SUCCESS);
  248.     }
  249.  AEPutStr("\r\nLAST CHANCE!   (Enter) to Start, (G)oodbye after transfer, (A)bort? ");
  250.  do {
  251.         mystat=Check_Online_Status();
  252.         if(mystat<0)  return(mystat);
  253.         mystat=ReadChar(KEYBOARD_TIMEOUT);
  254.  
  255.         if(mystat<(-1))         return(NO_CARRIER);
  256.  
  257.          if((mystat==65) || (mystat==97)) {
  258.             AEPutStr("Abort!\r\n\r\n");
  259.             return(SUCCESS);
  260.         }
  261.          if((status=='l' || status=='L') && XIMPort==CONSOLE_PORT) {
  262.             LocalUpload=1; status=13; break;
  263.          }
  264.     } while(((mystat!=13L)&&(mystat!=71L)&&(mystat!=103L)));
  265.  
  266.  if(mystat!=13)    AEPutStr("Goodbye!\r\n\r\n");
  267.  else     AEPutStr("\r\n\r\n");
  268.  
  269. SysopDL:
  270.  
  271.  DTBT=0;
  272.  TBT=0;
  273.  TTTM=NULL;
  274.  TTEFF=NULL;
  275.  TTCPS=NULL;
  276.  
  277.  if(!BeenUDd) {
  278.         DisplayUserToCallersLog(1);
  279.         BeenUDd=1;
  280.     }
  281.  
  282.  status=DownloadFile(rfinal);
  283.  
  284.  
  285.  if(status!=0)
  286.         flaglist[0]='\0';
  287.  
  288.  AEPutStr("\r\n\r\nFile transfer Completed.\r\n");
  289.  peff=NULL;
  290.  pcps=NULL;
  291.  if(Online_NFiles!=NULL)    {
  292.         peff=(TTEFF/Online_NFiles);
  293.         pcps=(TTCPS/Online_NFiles);
  294.     }
  295. // (RTS) added dnload cps rate Fri Mar 27 13:13:29 1992
  296.  if( (pcps > (long) User_keys.DNcps) || (User_keys.DNcps > 5000)) {
  297.         User_keys.DNcps = (UWORD) pcps;
  298.  
  299.         /* is this baud higher then max cps up ? */
  300.  }
  301.  if(status==0 && !User.XferProtocol)
  302.  {
  303.     if(ZModemInfo.Filesize==ZModemInfo.RecPos)
  304.     {
  305.       TBT += ZModemInfo.Filesize;
  306.       DTBT +=ZModemInfo.Filesize;
  307.       DONF +=1;
  308.     CallersLog("\tIncomplete 100% Transfer, accumilating Maximum Bytes Downloaded\n");
  309.     UDLog("\tIncomplete 100% Transfer, accumilating Maximum Bytes Downloaded\n");
  310.  
  311.     }
  312.       
  313.  }
  314.  sprintf(string," %d files, %ldk bytes, %ld minutes %ld seconds %ld cps, %ld %% efficiency at %ld"
  315.         ,Online_NFiles,(TBT/1024L),(TTTM/60L),(TTTM%60L),pcps,peff,Online_Baud);
  316.  
  317.      if(FreeDownloads)
  318.      {
  319.          my_struct.sessiondbytes += DTBT;   /* add dnloaded bytes to totalsession bytes */
  320.         User.Bytes_Download+=DTBT;
  321.         User.Downloads=User.Downloads+DONF;
  322.     }    User.Daily_Bytes_Dld+=DTBT;
  323.         BytesADL-=DTBT;
  324.  
  325.  AEPutStr(string);
  326.  AEPutStr("\r\n\r\n");
  327.  
  328.  strcpy(str,"\t");
  329.  strcat(str,string);
  330.  strcat(str,"\n");
  331.  if(Online_NFiles>0)    {
  332.         (void)CallersLog(str);
  333.         (void)UDLog(str);
  334.     } else {
  335.      (void)CallersLog("\tDownload Failed..\n");
  336.         (void)UDLog("\tDownload Failed..\n");
  337.     }
  338.  
  339.  DisplayULStats(&User);          /* Show User stats.. Num Dnloads, uploads */
  340.  AEPutStr("\r\n");
  341.  
  342.  StatPrintUser(&User);
  343.  if((mystat==71L)||(mystat==103L))  return(PGoodbye());
  344.  return(SUCCESS);
  345. }
  346.